#!/usr/local/bin/python2.5

_Copyright = "Copyright @ 2010 Michael P. Reilly. All rights reserved."

_SCM_ID = "$Id$"

from google.appengine.ext import db
from google.appengine.api import users

__all__ = [
  'getbykey',
  'OSDBUser', 'OSDBPassword', 'OSDBSeed', 'OSDBLabels', 'OSDBTypes',
  'OSDBImage', 'SeedLabelMap',
]

def getbykey(value):
    keyval = db.Key(encoded=value)
    return db.get(keyval)

class OSDBTypes(db.Model):
    # key = name
    name = db.StringProperty(required=True)
    comment = db.TextProperty()

class StockMd5s(db.Model):
    # key = (iname)
    iname = db.StringProperty(required=True)
    md5 = db.StringProperty(required=True)

class OSDBImage(db.Model):
    # key = (author, itype, iname)
    author = db.UserProperty(required=True)
    itype = db.BooleanProperty(required=True) # false is stock
    iname = db.StringProperty(required=True)
    md5 = db.StringProperty()

class OSDBUser(db.Model):
    # key = author
    author = db.UserProperty(required=True)
    securityQuestion = db.StringProperty()
    securityAnswer = db.StringProperty()
    pswd = db.ReferenceProperty(OSDBImage)

class OSDBLabels(db.Model):
    # key = (author, name)
    author = db.UserProperty(required=True)
    name = db.StringProperty(required=True)

class OSDBPassword(db.Model):
    # key = .key()
    author = db.UserProperty(required=True)
    pswd = db.StringProperty(required=True)

class OSDBSeed(db.Model):
    # key = (author, name) ?
    author = db.UserProperty(required=True)
    name = db.StringProperty(required=True)
    type = db.StringProperty(required=True)
    url = db.StringProperty()
    username = db.StringProperty()
    password = db.ReferenceProperty(OSDBPassword)
    comment = db.TextProperty()

class SeedLabelMap(db.Model):
    # none
    seed = db.ReferenceProperty(OSDBSeed, required=True)
    label = db.ReferenceProperty(OSDBLabels, required=True)

